package patienceSSO.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import patienceCommon.pojo.User;
import patienceCommon.vo.JsonMsg;
import patienceSSO.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserService userService;

	//JSONObject是阿里爸爸家的fastjson
	//用户登陆
	@RequestMapping("/landing")
	@ResponseBody
	public JsonMsg userLand(String account,String password) {
		JsonMsg msg=new JsonMsg();
		List<User> list=userService.landing(account,password);
		if(list==null||list.size()==0) {
			msg.setMsg("登陆失败");
			msg.setSuccess(false);
		}else {
			msg.setMsg("登陆成功");
			msg.setSuccess(true);
		}
		return msg;
	}

	// 注册验证账号或者邮箱
	@RequestMapping("/check")
	@ResponseBody
	public JsonMsg check(String account,String email) {
		JsonMsg msg=new JsonMsg();
		List<User> list=userService.check(account,email);
		if(list==null||list.size()==0){
			msg.setMsg("信息未保存");
			msg.setSuccess(true);
		}else {
			msg.setMsg("信息已存在");
			msg.setSuccess(false);
		}
		return msg;
	}

	// 用户保存注册信息，前台传部分数据，后台统一接收
	@RequestMapping("/saveUser")
	@ResponseBody
	public JsonMsg saveUser(String account,String username,String password,String phone,String email) {
		JsonMsg msg=new JsonMsg();
		int count=userService.add(account,username,password,phone,email);
		if(count>0){
			msg.setMsg("保存成功");
			msg.setSuccess(true);
		}else {
			msg.setMsg("保存失败");
			msg.setSuccess(false);
		}
		return msg;
	}

}
